package com.by.course.serivce.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by.course.entity.bo.BaseStudentCourse;
import com.by.course.mapper.BaseStudentCourseMapper;
import com.by.course.serivce.BaseCourseService;
import com.by.course.serivce.BaseStudentCourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class BaseStudentCourseServiceImpl extends ServiceImpl<BaseStudentCourseMapper, BaseStudentCourse> implements BaseStudentCourseService {

    @Resource
    private BaseStudentCourseMapper baseStudentCourseMapper;

    @Resource
    private BaseStudentCourseService baseStudentCourseService;

    @Override
    public void saveBatchByCourseIdList(List<Long> courseIdList, Long userId) {
        List<BaseStudentCourse> baseStudentCourseList = courseIdList.stream().map(t -> {
            BaseStudentCourse baseStudentCourse = new BaseStudentCourse();
            baseStudentCourse.setCourseId(t);
            baseStudentCourse.setUserId(userId);
            return baseStudentCourse;
        }).collect(Collectors.toList());
        baseStudentCourseService.saveBatch(baseStudentCourseList);
    }
}
